/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import entities.Franchise;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.Query;

/**
 *
 * @author Eduardo
 */

@Stateless
public class FranchiseDAO extends GeneralDAO<Franchise> {

    public Franchise searchById(String id) {
        Query q = em.createQuery("SELECT f FROM franchise AS f "
                + "  WHERE f.idFranchise = :id");
        q.setParameter("id", id);
        List<Franchise> results = q.getResultList();
        if (results == null) {
            return null;  // No encontrado
        } else if (results.size() != 1) {
            return null; // No encontrado
        } else {
            return results.get(0);  // Devuelve el encontrado
        }
    }
    
    public Franchise searchByDescription(String description) {
        Query q = em.createQuery("SELECT f FROM franchise AS f "
                + "  WHERE f.description = :description");
        q.setParameter("description", description);
        List<Franchise> results = q.getResultList();
        if (results == null) {
            return null;  // No encontrado
        } else if (results.size() != 1) {
            return null; // No encontrado
        } else {
            return results.get(0);  // Devuelve el encontrado
        }
    }


    public List<Franchise> searchAll() {
        Query q = em.createQuery("SELECT f FROM franchise as f");
        return q.getResultList();
    }

}
